import { createApp } from 'vue'
import App from './App.vue'
import 'vfonts/Lato.css'
import 'vfonts/FiraCode.css'
import './Css/base.css'
import 'font-awesome/css/font-awesome.min.css'
import axios from 'axios'
import VueAxios from 'vue-axios'
import router from "./Router";
import naive from "naive-ui";
import utils from "@/Utils";
/*const naive = create({
    components: [NButton,darkTheme]
})*/
axios.defaults.baseURL="http://localhost:10000/springMVCProject_war_exploded"
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    config.headers.token=localStorage.getItem("token")
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    const data=response.data;
    if (utils.isNoLogin(data.code, data.status)) {
        localStorage.removeItem("token")
        localStorage.removeItem("role")
        router.push("/Login")
        return
    }
    if (utils.isNoRole(data.code,data.status)){
        router.push("/index")
        return;
    }
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
const mount=createApp(App)

mount.use(naive)
    .use(router)
    .use(utils)
    .use(VueAxios, axios)
    .mount('#app')
mount.config.globalProperties.$utils=utils;